#pragma once

#include "i_base.h"

namespace idl
{
  /*This class is mostly used for online real-time visual tracking, the actual implementation is real-time speed driven*/
  class FastHarrisDetector
  {
  public:
    FastHarrisDetector();
    FastHarrisDetector(int width, int height);
    ~FastHarrisDetector();
    
    /*Get the maximum number of features ever detected*/
    int getMaxNrFeatures() const;
    bool init(int width, int height);
    
    /*Specify the maximum number of features that can be supported by this class.
      Return that number back*/
    int setMaxNrFeatures(int nr); 

    /*Specify the number of divided image blocks used for sorting the features -- to make the feature distribution more uniform.
    The minimum allowed block size is 4x4;
    Return the actual total number of blocks*/
    int setNrBlocks(int nrbh, int nrbv);

    void setRoi(int left, int top, int right, int bottom);

    ///*Perform harris corner detection in im. The image is divided into mxn blocks and each block can have maximum _max_nr_fea/(mxn) features.
    //  Return number of features extracted, which can be up to _max_nr_fea*/
    //int detect(const unsigned char *const *image, float* coords, float abs_threshold);

    /*Perform harris corner detection in image. The image is divided into mxn blocks and each block can have maximum _max_nr_fea/(mxn) features.
    Return number of features extracted, which can be up to _max_nr_fea*/
    int detect(const unsigned char *const *image, int* coords, float abs_threshold);

    /*Perform harris corner detection in image. The image is divided into mxn blocks and each block can have maximum _max_nr_fea/(mxn) features.
    Return number of features extracted, which can be up to _max_nr_fea*/
    int detect(const unsigned char *const *image, unsigned short* coords, float abs_threshold);

  protected:
    void cleanup();
    bool allocMemory(int m, int n);
  protected:
    int _max_nr_fea, _width, _height, _roi[4];
    int _nr_hor_blocks, _nr_ver_blocks;
    float **_strength, *_mem, *_tempf;
    int *_tempi;
  };
}/* namespace idl */